package com.ruoyi.labdata.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.labdata.mapper.LabInstrumentShiftMapper;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.labdata.domain.LabInstrumentShift;
import com.ruoyi.labdata.domain.LabOrgnization;
import com.ruoyi.labdata.service.ILabInstrumentShiftService;
import com.ruoyi.labdata.service.ILabOrgnizationService;
import com.ruoyi.system.domain.Instrumentation;
import com.ruoyi.system.service.IInstrumentationService;

/**
 * 仪器迁移Service业务层处理
 * 
 * @author winner pan
 * @date 2022-03-02
 */
@Service
public class LabInstrumentShiftServiceImpl implements ILabInstrumentShiftService 
{
    @Autowired
    private LabInstrumentShiftMapper labInstrumentShiftMapper;
    @Autowired
    private IInstrumentationService instrumentationService;
    @Autowired
    private ILabOrgnizationService labOrgnizationService;

    /**
     * 查询仪器迁移
     * 
     * @param shiftId 仪器迁移ID
     * @return 仪器迁移
     */
    @Override
    public LabInstrumentShift selectLabInstrumentShiftById(Long shiftId)
    {
        return labInstrumentShiftMapper.selectLabInstrumentShiftById(shiftId);
    }

    /**
     * 查询仪器迁移列表
     * 
     * @param labInstrumentShift 仪器迁移
     * @return 仪器迁移
     */
    @Override
    public List<LabInstrumentShift> selectLabInstrumentShiftList(LabInstrumentShift labInstrumentShift)
    {
        return labInstrumentShiftMapper.selectLabInstrumentShiftList(labInstrumentShift);
    }

    /**
     * 新增仪器迁移
     * 
     * @param labInstrumentShift 仪器迁移
     * @return 结果
     */
    @Override
    @Transactional
    public int insertLabInstrumentShift(LabInstrumentShift labInstrumentShift){
    	Instrumentation instrumentation = new Instrumentation();
    	instrumentation.setInstrumentationId(labInstrumentShift.getInstrumentationId());
    	instrumentation.setLabId(labInstrumentShift.getTargetLabId());
    	LabOrgnization org = labOrgnizationService.selectLabOrgnizationById(labInstrumentShift.getTargetLabId());
    	instrumentation.setSuperOrgId(org.getParentId());
    	instrumentationService.updateInstrumentation(instrumentation);
    	labInstrumentShift.setOperatorId(SecurityUtils.getLoginUser().getUser().getUserId());
    	return labInstrumentShiftMapper.insertLabInstrumentShift(labInstrumentShift);
    }

    /**
     * 修改仪器迁移
     * 
     * @param labInstrumentShift 仪器迁移
     * @return 结果
     */
    @Override
    public int updateLabInstrumentShift(LabInstrumentShift labInstrumentShift)
    {
        return labInstrumentShiftMapper.updateLabInstrumentShift(labInstrumentShift);
    }

    /**
     * 批量删除仪器迁移
     * 
     * @param shiftIds 需要删除的仪器迁移ID
     * @return 结果
     */
    @Override
    public int deleteLabInstrumentShiftByIds(Long[] shiftIds)
    {
        return labInstrumentShiftMapper.deleteLabInstrumentShiftByIds(shiftIds);
    }

    /**
     * 删除仪器迁移信息
     * 
     * @param shiftId 仪器迁移ID
     * @return 结果
     */
    @Override
    public int deleteLabInstrumentShiftById(Long shiftId)
    {
        return labInstrumentShiftMapper.deleteLabInstrumentShiftById(shiftId);
    }
}
